#include<iostream>
using namespace std;
void Print(int a[], int n)
{
	int i = 0;
	for (i; i < n; i++)
	{
		cout << a[i] << ' ';
	}
	cout << endl;
}
void ShellSort(int a[], int n,int ngap[])
{
	int k = 0;
	for(k;k<3;k++)
	{
		int gap = ngap[k];
		int i = 0;
		for (i; i < n; i++)
		{
			int j = i;
			while (j - gap >= 0 && a[j] < a[j - gap])
			{
				std::swap(a[j], a[j - gap]);
				j -= gap;
			}
		}
		Print(a, n);
		
	}
}
int main()
{
	int n = 0;
	int a[200] = { 0 };
	int gap[3];
	while (1)
	{
		int x;
		cin >> x;
		if (x == 0)
			break;
		a[n++] = x;
	}
	int i = 0;
	for (i; i < 3; i++)
	{
		cin >> gap[i];
	}
	ShellSort(a, n,gap);
}